package com.authine.cloudpivot.ext.applicationservice;

import com.authine.cloudpivot.ext.dto.OrderCustomerGoodsDto;
import com.authine.cloudpivot.ext.dto.OrderVendorGoodDto;
import com.authine.cloudpivot.ext.dto.PageObject;
import com.authine.cloudpivot.ext.utils.JdbcUtil;
import com.authine.hermes.app.launcher.response.SingleResponse;
import com.authine.hermes.app.launcher.service.ApplicationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.util.List;
import java.util.Map;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

@Slf4j
@Path("TodoGoodService")
public class TodoGoodService extends ApplicationService {

    @Path("queryToReceiveGood")
    @POST
    @Operation(summary = "待收货",tags = CUSTOM_SERVICE)
    public SingleResponse queryToReceiveGood(@Parameter OrderCustomerGoodsDto good){
        PageObject<Map<String,Object>> pageObject = new PageObject<Map<String,Object>>();
        try{
            Integer pageCurrent = good.getPageCurrent() == null ?  1: good.getPageCurrent();
            Integer pageSize = good.getPageSize() == null ? 10 : good.getPageSize();
            // 设置当前页
            good.setPageCurrent(pageCurrent);
            // 设置每页显示的条数
            pageObject.setPageSize(pageSize);
            // 设置总记录数

            int count = JdbcUtil.getRceiveGoodCount(good);
            log.info("总条数:{}"+count);
            pageObject.setRowCount(count);
            pageObject.setPageCount(0);
            if (count != 0 ){
                // 设置总页数
                int pageNum = count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1;
                pageObject.setPageCount(pageNum);
                // 设置每页显示数据集合
                // 开始的记录数
                int start = (pageCurrent - 1) * pageSize;
                System.out.println(start+"-"+pageSize);
                List<Map<String, Object>> orderList = JdbcUtil.getReceiveGoodList(good, start, pageSize);
                pageObject.setData(orderList);
            }else{
                pageObject.setPageCount(0);
                pageObject.setData(null);
            }
        }catch (Exception e){
            log.info("查询出错",e);
        }
        return SingleResponse.of(pageObject);
    }

}
